angular.module('app.baseinfo')

    .factory('locationService', ["$http", "config", function ($http, config) {

        var baseUrl = config.baseUrl;

        var ret = {};

        ret.getLocation=function(query){
            var url=baseUrl+"/locations";
            return $http.get(url,{params:query});
        };

        ret.addLocation=function(location){
            var url=baseUrl+"/locations";
            return $http.post(url, location);
        };

        ret.deleteLocation=function(location){
            var url=baseUrl+"/locations/"+location.id;
            return $http.delete(url);
        };

        ret.getAreas=function(query){
            var url=baseUrl+"/locationAreas";
            return $http.get(url,{params:query});
        };

        ret.addArea=function(area){
            var url=baseUrl+"/locationAreas";
            return $http.post(url, area);
        };

        ret.editArea=function(area){
            var url=baseUrl+"/locationAreas/"+area.id;
            return $http.post(url, area);
        };

        ret.deleteArea=function(area){
            var url=baseUrl+"/locationAreas/"+area.id;
            return $http.delete(url);
        };
        return ret;
    }]);